package org.yourorghere;


import java.util.ArrayList;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author mark_o
 */
public class ShkalaJOGLRenderer implements GLEventListener {

    //public static ArrayList<Double> Results;
    //public static ArrayList<Node> NodeList;
    //public static ArrayList<Triangle> TrList;
    public static double max;
    public static double min;

    public void init(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();
        System.err.println("INIT GL IS: " + gl.getClass().getName());

        // Enable VSync
        gl.setSwapInterval(1);

        // Setup the drawing area and shading mode
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
        gl.glOrtho(-0.5, 2.5, min, max, -1.0, 1.0);
            
    }

    public void display(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();
        double h = (max-min)/100;
        double cur = max;
        //gl.glTranslatef(0.0f, 0.0f, -16.0f);
        /*while(cur>=min){
        gl.glBegin(GL.GL_QUADS);
        if(cur>0){
        gl.glColor3d(0.0,(cur)/(max), 0.0);
        }else{
        if(Math.abs(cur)<0.1){
        gl.glColor3d(0.0, 0.0,Math.abs(cur)/Math.abs(min));
        }else{
        gl.glColor3d((cur)/(min),0.0, 0.0);
        }
        }
        gl.glVertex3d(0,cur,0 );
        gl.glVertex3d(1,cur,0 );
        cur-=h;
        if(cur>0){
        gl.glColor3d(0.0,(cur)/(max), 0.0);
        }else{
        if(Math.abs(cur)<0.1){
        gl.glColor3d(0.0, 0.0,Math.abs(cur)/Math.abs(min));
        }else{
        gl.glColor3d((cur)/(min),0.0, 0.0);
        }
        }
        gl.glVertex3d(1,cur,0 );
        gl.glVertex3d(0,cur,0 );

        gl.glEnd();
        }*/
        gl.glColor3d(1.0, 0.0, 0.0);
        gl.glBegin(GL.GL_QUADS);
            gl.glVertex3d(1,1,0 );
            gl.glVertex3d(0,1,0 );
            gl.glVertex3d(0,10,0 );
            gl.glVertex3d(1,10,0 );
        gl.glEnd();

        

    }

    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
                GL gl = drawable.getGL();
        GLU glu = new GLU();

        if (height <= 0) { // avoid a divide by zero error!

            height = 1;
        }
        final float h = (float) width / (float) height;
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluPerspective(45.0f, h, 1.0, 20.0);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
        gl.glOrtho(-0.5, 2.5, min, max, -1.0, 1.0);
    }

    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
        
    }

}
